import request from '@/utils/request'

// 用户注册
export function register(data) {
  return request({
    url: '/register',
    method: 'post',
    data
  })
}

// 用户登录
export function login(data) {
  console.log('准备发送登录请求:', {
    url: '/users/login',
    method: 'post',
    data,
    baseURL: request.defaults.baseURL
  });
  return request({
    url: '/users/login',
    method: 'post',
    data,
    timeout: 5000 // 增加超时设置
  })
}

// 获取当前用户 (兼容旧版本)
export const getCurrentUser = getUserProfile

// 获取用户资料
export function getUserProfile() {
  return request({
    url: '/users/me',
    method: 'get'
  })
}

// 更新用户资料
export function updateUserProfile(data) {
  return request({
    url: '/users/me',
    method: 'put',
    data
  })
}

// 获取下载记录
export function getDownloadHistory(params) {
  return request({
    url: '/user/downloads',
    method: 'get',
    params
  })
}

// 获取虚拟币余额
export function getCoinBalance() {
  return request({
    url: '/user/coins/balance',
    method: 'get'
  })
}

// 获取充值记录
export function getRechargeHistory() {
  return request({
    url: '/user/coins/recharges',
    method: 'get'
  })
}

// 获取消费记录
export function getConsumptionHistory() {
  return request({
    url: '/user/coins/consumptions',
    method: 'get'
  })
}

// 重置密码
export function resetPassword(data) {
  return request({
    url: '/reset-password',
    method: 'post',
    data
  })
}

// 发送注册验证码
export function sendRegisterCode(data) {
  return request({
    url: '/send-register-code',
    method: 'post',
    data
  })
}

// 发送重置密码验证码
export function sendResetPasswordCode(data) {
  return request({
    url: '/send-reset-password-code',
    method: 'post',
    data
  })
}